.import fan.qt.complex 1.0 as Lex


function login()
{
    if (accountTxt.text.trim().length === 0){
        dialog.message("登录账号不能为空!");
        return;
    }

    if (passText.text.trim().length === 0)
    {
        dialog.message("登录密码不能为空!");
        return;
    }

    nav.initializeTask(0, 2, "正在登录账号")

    nav.openTask("登录账号");

    http.get("/member.json?t=auth", {name: accountTxt.text.trim(),
                      password: Qt.md5(passText.text.trim()).toUpperCase(),
                       school: xmlModel_School.get(txtCompany.currentIndex).id
                  }, result)

     nav.value++
}

function result(json) {
    nav.value = nav.maximumValue

    if (json.error) {
        dialog.message(json.error.description)
        return
    }

    usinfo.id = json.id
    usinfo.role = json.role
    usinfo.name = json.name
    usinfo.initialized = true
    usinfo.token = json.token

    usinfo.address = json.address
    usinfo.mail = json.mail
    usinfo.mobile =json.mobile
    usinfo.identity = json.indentity
    usinfo["school"] = json.school
    usinfo["parent"]  = json.parent
    usinfo.image =  "http://" + Lex.G.SERVER + json.image

   usinfo.role = json.role

    if (usinfo.role == "t") {
         usinfo.displayRole = "教练"
         model = objectModelM1
    }
    else {
        usinfo.displayRole = "学员"
    }

    contentArea.navigate("../qml/MainPageNavigator.qml");
}

function goUI (){
    if (directqml)
    {
        contentArea.replace(Qt.resolvedUrl(directqml));
    }
}

function register()
{
    contentArea.navigate("../qml/MemberRegisterNavigator.qml");
}

function recover()
{
    contentArea.navigate("../qml/MemberRecoverNavigator.qml");
}

